<?php

namespace Kateba\SiteBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Question
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Kateba\SiteBundle\Entity\QuestionRepository")
 */
class Question {

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     * @Assert\NotBlank
     * @Assert\MinLength(limit=5)
     * @ORM\Column(name="question", type="string", length=255)
     */
    private $question;
    
    /**
     * @var text
     * @ORM\Column(name="questionDetails", type="text",nullable=true)
     */
    private $questionDetails;

    /**
     * @var \Kateba\SiteBundle\Entity\Answer[]
     *
     * @ORM\OneToMany(targetEntity="\Kateba\SiteBundle\Entity\Answer", mappedBy="question", cascade={"remove"}, orphanRemoval=true)
     */
    private $answers;

    /**
     * @var \Kateba\UserBundle\Entity\User
     *
     * @ORM\ManyToOne(targetEntity="\Kateba\UserBundle\Entity\User", inversedBy="questions")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
     */
    private $user;

    /**
     * @var boolean
     *
     * @ORM\Column(name="approved", type="boolean")
     */
    private $approved = false;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="createdAt", type="datetime")
     */
    private $createdAt;

    public function __toString() {
        return (string) $this->question;
    }

    public function __construct() {
        $this->createdAt = new \DateTime();
        $this->answers = new ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId() {
        return $this->id;
    }

    /**
     * Set question
     *
     * @param string $question
     * @return Question
     */
    public function setQuestion($question) {
        $this->question = $question;

        return $this;
    }

    /**
     * Get question
     *
     * @return string
     */
    public function getQuestion() {
        return $this->question;
    }

    /**
     * Set approved
     *
     * @param boolean $approved
     * @return Question
     */
    public function setApproved($approved) {
        $this->approved = $approved;

        return $this;
    }

    /**
     * Get approved
     *
     * @return boolean
     */
    public function getApproved() {
        return $this->approved;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return Question
     */
    public function setCreatedAt($createdAt) {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime
     */
    public function getCreatedAt() {
        return $this->createdAt;
    }

    /**
     * Add answers
     *
     * @param \Kateba\SiteBundle\Entity\Answer $answers
     * @return Question
     */
    public function addAnswer(\Kateba\SiteBundle\Entity\Answer $answers) {
        $this->answers[] = $answers;

        return $this;
    }

    /**
     * Remove answers
     *
     * @param \Kateba\SiteBundle\Entity\Answer $answers
     */
    public function removeAnswer(\Kateba\SiteBundle\Entity\Answer $answers) {
        $this->answers->removeElement($answers);
    }

    /**
     * Get answers
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getAnswers() {
        return $this->answers;
    }

    /**
     * Set user
     *
     * @param \Kateba\UserBundle\Entity\User $user
     * @return Question
     */
    public function setUser(\Kateba\UserBundle\Entity\User $user) {
        $this->user = $user;

        return $this;
    }

    /**
     * Get user
     *
     * @return \Kateba\UserBundle\Entity\User
     */
    public function getUser() {
        return $this->user;
    }


    /**
     * Set questionDetails
     *
     * @param string $questionDetails
     * @return Question
     */
    public function setQuestionDetails($questionDetails)
    {
        $this->questionDetails = $questionDetails;
    
        return $this;
    }

    /**
     * Get questionDetails
     *
     * @return string 
     */
    public function getQuestionDetails()
    {
        return $this->questionDetails;
    }
}